﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Portal.Systems.Model;

namespace Portal.Web.Utility
{
    public class WebSessionUtility
    {
        public static void SetCurrentLoginUser(UserCls OUser)
        {
            System.Web.HttpContext.Current.Session["User"] = OUser;
        }

        public static UserCls GetCurrentLoginUser()
        {
            return (UserCls)System.Web.HttpContext.Current.Session["User"];
        }


        public static void SetSession(string SiteId, string Key, object Value)
        {
            System.Web.HttpContext.Current.Session[SiteId + Key] = Value;            
        }

        public static object GetSession(string SiteId, string Key)
        {
            return System.Web.HttpContext.Current.Session[SiteId + Key];
        }

        public static void CheckSessionTimeOut()
        {
            if (GetCurrentLoginUser() == null)
            {
                throw new Exception("Session timeout. Xin vui lòng đăng nhập lại!");
            }
        }

        public static bool IsSessionTimeOut()
        {
            return GetCurrentLoginUser() == null;
        }
    }
}
